import wx
class ButtonFrame(wx.Frame):  
    def __init__(self):  
        wx.Frame.__init__(self, None, -1, title='MSSQLConnect',size=(800,600))  
        panel = wx.Panel(self, -1)
        a = self.coordinate(15)       
        for key in a:
            wx.Button(self,a[key][-1],label=key,pos=(a[key][0][0],a[key][0][1]),size=(100,40))
            self.Bind(wx.EVT_BUTTON, self.OnClick, id=a[key][-1])  
             
         
        #self.Bind(wx.EVT_BUTTON, self.OnClick, self.button)  
        #self.button.SetDefault()
   
    def OnClick(self, event):
        print ("Click! (%d)\n" % event.GetId())
         
         
    def Autolist(self,count2,argument):
        l =[]
        for i in range(count2):
            l.append(i*argument)
        return l            
         
         
    def coordinate(self,count):
        ##坐标可选择列表返回或者是字典返回，需修改
        d = {}
        l= []
        N = count/14
        n = count%14
        X = N*100
        if N != 0:
            for y in self.Autolist(14,40):
                for x in self.Autolist(N,100):
                    l.append((x,y))
                    d["Button%s,%s"%(x,y)]=[(x,y)]
            for z in self.Autolist(n,40):
                d["Button%s,%s"%(X,z)]=[(X,z)]
                l.append((X,z))
        else :
            for i in self.Autolist(n,40):
                d["Button%s,%s"%(0,i)]=[(0,i)]
                l.append((0,i))
        n = 0
        for key in d:
            n = n+1
            d[key].append(n)
             
             
        print d
        return d    
           
def runTest(frame, nb, log):
    win = TestPanel(nb, log)
    return win
 
if __name__ == '__main__':  
    app = wx.PySimpleApp()  
    frame = ButtonFrame()
    frame.Show()  
    app.MainLoop()